home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Plug-In Power Pack for Netscape Communicator
/
Plug-In Power Pack for Netscape Communicator.iso
/
plugins
/
dataviews
/
dvdraw
/
examples
/
datasource
/
parser.cpp
< prev
next >
Wrap
C/C++ Source or Header
|
1997-05-23
|
4KB
|
183 lines
// Parser.cpp : Code that reads the variable defintion file. This code is
// segregated for simply pedantic purposes in that it might
// detract a user from understanding the real purpose of this
// example, which is to show how a data source browser is expected
// to interface with DV-Draw (and not how to parse a data file!).
//
#include "stdafx.h"
#include "ExampleDsDll.h"
#include "VUfundecl.h"
#define READ_BUFSIZE 256
#define COMMENT_SYMBOL '#'
#define PLACE_HOLDER '*'
#define SKIPSPACES(x) for( ; (*x == ' ') || (*x == '\t'); (x)++)
#define SKIPTOSPACE(x) for( ; (*x != ' ') && (*x != NULL) && (*x != '\t'); (x)++)
#define LINE_OK(x) ( *x != COMMENT_SYMBOL && *x != '\n' )
////////////////////////////////////////////////////////////////////////////////
//
// OpenDataFile
//
BOOL CExampleDsDll::OpenDataFile(CStdioFile& cFile)
{
char *dvHome = 0;
if( (VURegQueryDvHome(&dvHome)) == ERROR_SUCCESS)
{
CString csSuffix("\\DVdraw\\examples\\DataSource\\VarDefs.dat");
CString csVarFile = dvHome;
csVarFile += csSuffix;
free(dvHome);
return cFile.Open((LPCTSTR)csVarFile, CFile::modeRead);
}
return FALSE;
}
////////////////////////////////////////////////////////////////////////////////
//
// LookupBaseAddr
//
// Since its such a small number of types, we'll just brute force it...
//
ADDRESS CExampleDsDll::LookupBaseAddr(int data_type)
{
for(int i =0;i<NUM_DATA_TYPES && data_type != m_TypeTable[i].type;i++);
return(m_TypeTable[i].addr);
}
////////////////////////////////////////////////////////////////////////////////
//
// LookupDataType
//
// Since its such a small number of types, we'll just brute force it...
//
char* CExampleDsDll::LookupDataType(char* string, int* type )
{
for(int i = 0;i<NUM_DATA_TYPES && strcmp(string,m_TypeTable[i].name);i++);
*type = m_TypeTable[i].type;
return( m_TypeTable[i].name2 );
}
////////////////////////////////////////////////////////////////////////////////
//
// GetNextWord
//
int CExampleDsDll::GetNextWord(char** start, char** end, BOOL term)
{
int len;
SKIPSPACES(*start);
*end = *start;
SKIPTOSPACE(*end);
len = (int)(*end - *start);
if( *end && term )
{
**end = '\0';
(*end)++;
}
return( len );
}
/////////////////////////////////////////////////////////////////////////////
//
// ReadVarDefinitions
//
void CExampleDsDll::ReadVarDefinitions()
{
char *start, *end, buffer[READ_BUFSIZE];
CString varName;
CStdioFile cFile;
VARDEFDATA* pLastEntry = 0;
if(!OpenDataFile(cFile))
return;
while(cFile.ReadString(buffer, READ_BUFSIZE))
{
VARDEFDATA* pData = 0;
start = buffer;
SKIPSPACES(start);
if( LINE_OK(start) )
{
// Get variable's name and allocate buffer space
GetNextWord( &start, &end, YES );
varName = start;
pData = new VARDEFDATA;
pData->next = 0;
// Set the head of the list
if(!m_pVarDefList)
m_pVarDefList = pData;
// Insert new entry at end of list
if(pLastEntry)
pLastEntry->next = pData;
// Remember this new entry as the last one...
pLastEntry = pData;
// Get variable type
start = end;
GetNextWord( &start, &end, YES );
pData->m_csVarTypeName = LookupDataType(start, &(pData->m_nVarType));
// Local data buffer we want to use...
pData->m_pBuffer = LookupBaseAddr(pData->m_nVarType);
// Get number of rows...
start = end;
GetNextWord( &start, &end, YES );
if( start[0] == PLACE_HOLDER )
pData->m_nRows = 1;
else
pData->m_nRows = max(1, atoi(start));
// ...and columns.
start = end;
GetNextWord( &start, &end, YES );
if( start[0] == PLACE_HOLDER )
pData->m_nCols = 1;
else
pData->m_nCols = max(1, atoi(start));
// Get low value...
start = end;
GetNextWord( &start, &end, YES );
if( start[0] == PLACE_HOLDER )
pData->m_dLowRange = 0.0;
else
pData->m_dLowRange = atof( start );
// ...and high value
start = end;
GetNextWord( &start, &end, YES );
if( start[0] == PLACE_HOLDER )
pData->m_dHighRange = 1.0;
else
pData->m_dHighRange = atof( start );
SetVarTagName(pData, (LPCTSTR)varName);
}
}
cFile.Close();
}